<?php

namespace app\index\controller;

use think\Controller;
use think\Db;

class Center extends Controller
{
    public function index(){
        if(input('param.buybook')){
            echo "<script>alert('请先完善收货地址');</script>";
        }
        $userMsg=Db::name('usermsg')->where('usermsg_user_id',session('user_id'))->find();
        if(!$userMsg){
            $userMsg="";
        }
        $payBook=Db::name('pay')->where('pay_user_id',session('user_id'))->where('pay_payed',1)->select();
        if(!$payBook){
            $payBook="";
        }else{
            foreach ($payBook as $k=>$v){
                $payBook[$k]['book']=Db::name('book')->where('book_id',$v['pay_book_id'])->find();
            }
        }
        $liveRes=Db::name('livereserve')->where('livereserve_user_id',session('user_id'))->select();
        $this->assign('payBook',$payBook);
        $this->assign('userMsg',$userMsg);
        $this->assign('liveRes',$liveRes);
        return $this->fetch();
    }
    public function saveMsg(){
        $data=input('param.');
        $userMsg['usermsg_user_id']=session('user_id');
        $userMsg['usermsg_nickname']=$data['nickname'];
        $userMsg['usermsg_address']=$data['province']."省".$data['city']."市".$data['xian']."县".$data['address'];

        $checkMsg=Db::name('usermsg')->where('usermsg_user_id',$userMsg['usermsg_user_id'])->find();
        if($checkMsg){
            Db::name('usermsg')->where('usermsg_user_id',$userMsg['usermsg_user_id'])->update($userMsg);
        }else{
            Db::name('usermsg')->insert($userMsg);
        }
        $this->redirect('index/center/index');
    }
}
